package gold.digger;

import gold.utils.InputUtil;
import javafx.util.Pair;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2225 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public List<List<Integer>> findWinners(int[][] matches) {
            Map<Integer, int[]> contestMap = new HashMap<>();
            for (int[] match : matches) {
                int winnerId = match[0], loserId = match[1];
                if (!contestMap.containsKey(winnerId)) contestMap.put(winnerId, new int[]{0, 0});
                if (!contestMap.containsKey(loserId)) contestMap.put(loserId, new int[]{0, 0});
                contestMap.get(winnerId)[0]++;
                contestMap.get(loserId)[1]++;
            }

            List<List<Integer>> ans = new ArrayList<>();
            List<Integer> allWin = new ArrayList<>(), loseOne = new ArrayList<>();
            for (Integer id : contestMap.keySet()) {
                if (contestMap.get(id)[1] == 0) allWin.add(id);
                if (contestMap.get(id)[1] == 1) loseOne.add(id);
            }

            Collections.sort(allWin);
            Collections.sort(loseOne);
            ans.add(allWin);
            ans.add(loseOne);
            return ans;
        }
    }

    public void run() {
        System.out.println(new Solution().findWinners(InputUtil.toDoubleIntegerArray("[[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]")));
        System.out.println(new Solution().findWinners(InputUtil.toDoubleIntegerArray("[[2,3],[1,3],[5,4],[6,4]]")));
    }

    public static void main(String[] args) throws Exception {
        LC2225 an = new LC2225();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
